// 创建了 7 个对象，将其与html页面元素关联
let phoneNumberInput = document.querySelector("#phoneNumber");
let linkButton = document.querySelector("#verify_link");
let verifyLink = document.querySelector(".row1_1");
let passwordInput1 = document.querySelector("#password1");
let passwordInput2 = document.querySelector("#password2");
let authorizeInput = document.querySelector("#authorize");
let submitButton = document.querySelector("#submit");

linkButton.onclick = function() {
    $.ajax({
        // 发送请求
        type: 'post',
        url: '/verify',
        data: {
            phoneNumber: phoneNumberInput.value,
        },

        // 接收响应
        success: function(body) {
            if (body == 1) {
                console.log(body);
                verifyLink.innerHTML = '<a class="row1_1" target="_blank" href="verify.html">https:gobang.org/dfg=&57a/JAID</a>';
            } else if (body == 2) {
                console.log(body);
                alert("号码格式错误！");
            } else {
                console.log(body);
                alert("该号码已被注册！");
            }
        },
        error: function() {
            alert("验证失败1！");
        }
    });
}
submitButton.onclick = function() {
    $.ajax({
        // 发送请求
        type: 'post',
        url: '/register2',
        data: {
            phoneNumber: phoneNumberInput.value,
            authorize_num: authorizeInput.value,
            password1: passwordInput1.value,
            password2: passwordInput2.value,
        },

        //接收响应
        success: function(body) {
            if (body == 2) {
                alert("授权码错误！");
            } else if (body == 3) {
                alert("两次密码不相同！");
            } else {
                alert("注册成功！");
                location.assign("/login.html");
            }
        },
        error: function() {
            alert("注册失败1！");
        }
    });
}